/** 
*@author Raymond 
*@version 2012 - 01 - 22
 control class of rolling a dice
 output the dice result
//*********************************************/
package dice;

import java.util.Random;

public class RollDice {

	private DiceWindow diceWindow;
	
	public RollDice() {
		diceWindow = new DiceWindow();
	}
	
	public int roll(int playerID) {
		int result=0;
		
		diceWindow.promptRollDice(playerID);
		result = generateValue();
		
		return result;
	}
	
	public int generateValue(){
		 	/**note a single Random object is reused here*/
		    Random randomGenerator = new Random();
	
		    /**Dice have 6 values*/
		    int randomInt = randomGenerator.nextInt(6)+1;
		    
		    diceWindow.printResult(randomInt);
		    return randomInt;
		  }
		  
	  /**
	  Second version of roll 
	  accept an integer as parameter
	  the n is the range of values you want to produce
	 e.g. if n = 2, the roll produce 2 result
	 //*********************************************/
	 public int roll2(int n) {
		 	/**note a single Random object is reused here*/
		    Random randomGenerator = new Random();
		   
		    int randomInt = randomGenerator.nextInt(n)+1;
		    return randomInt;
	 } 
}